var express = require('express')
const router = express.Router()
const path = require('path')
const fs = require('fs')
const util = require('../util/util')


router.use(function (req, res, next) {
    next()
})
var callObj = {
    callTaskRecordId: '001',
    callTime: '2020/05/20',
    callResultCode: '1',
    callDuration: '30000',
    callRecordFile: 'http://localhost:3000/%E6%88%91%E7%9A%84%E4%B8%80%E4%B8%AA%E9%81%93%E5%A7%91%E6%9C%8B%E5%8F%8B.mp3?',
    remark: '我是备注'
}

// 提交外呼表单
router.post('/submit', function (req, res) {
    res.send({
        code: 200,
        data: util.createList(callObj)
    });
})
// 保存呼叫记录
router.post('/saveLog', function (req, res) {
    res.send({
        code: 200,
        data: null
    })
})
// 外呼任务关注
router.post('/follow', function (req, res) {
    res.send({
        code: 200,
        data: null
    })
})
// 查询外呼详情
router.post('/recordDetail', function (req, res) {
    res.send({
        code: 200,
        data: {
            recordDetail: 1,
            cno: '9999',
            callTaskId: '100001',
            callTaskRecordId: "100001",
            firstCallTime: '1010/05/25',
            lastCallTime: '1010/05/26',
            taskType: '1',
            gmtCreated: '2020/05/25',
            taskName: '后台导入',
            phoneNumberAttribution: '上海',
            callDuration: '100',
            callPhoneNumber: '18334771358',
            callStatus: '外呼状态',
            recordStatus: '任务记录状态',
            outerCallNo: '外部呼叫编号',
            remark: '备注',
            isFocus: 'Y',
            userIntentLevel: 'HIGH',
            planCallTime: '1010/05/25',
            callResultCode: 'INVALID',
            callResultMsg: '外呼结果Msg',
            taskExtJson: JSON.stringify({ a: 1, b: 2, c: 3 }),
            sellGoodsList: [{
                sellGoodsId: util.mandomNum(),
                goodsId: '1',
                goodsName: '125项青中老年全身综合体检套餐',
                goodsType: 'CHECK',
                goodsSendTime: '2020/05/22 09:37:50',
                goodsOriginPrice: '100',
                goodsCurrentPrice: '10',
                goodsMinimumPrice: '80',
                goodsPayablePrice: '90',
                goodsPayPrice: '85',
                orderNo: util.mandomNum(),
                goodsOrderTime: '2020/05/22 09:37:50',
                goodsBuyCount: 20,
                goodsPayTime: '2020/05/22 09:37:50',
                sellGoodsStatus: 'SELL_GOODS_ORDER',
                sendSellGoodsContent: '【优健康】尊敬的张强强您好，为您推荐【热销爆款】125项青中老年全身综合体检套餐，点击下方链接进行购买t.cn/S2xt2g 退订回T'
            }]
        }
    })
})

// 查询外呼记录列表接口
router.post('/recordList', function (req, res) {
    var file = path.join(__dirname, '../', '/JSON/recordList.json'); //文件路径，__dirname为当前运行js文件的目录
    console.log('请求进来')
    //读取json文件
    fs.readFile(file, 'utf-8', function (err, data) {
        if (err) {
            res.send('文件读取失败');
        } else {
            res.send(data);
        }
    });
})
// 查询外呼记录列表接口
router.post('/countByTab', function (req, res) {
    res.send({
        code: 200,
        data: {
            planCount: '100',
            waitCount: "378",
            visitedCount: "213",
            callInCount: "2132"
        }
    })
})
// 查询外呼记录列表接口
router.post('/caller/getCurrentCaller', function (req, res) {
    res.send({
        code: 200,
        data: { identifier: 'whhz', cno: 9999, password: '12345678', bindTel: '0055', bindType: 3, loginStatus: 1 }
    })
})

module.exports = router